﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UcAccountList.ascx.cs"
    Inherits="TMT.Admin.UserAccount.UcAccountList" %>
<%@ Register Src="~/UserAccount/UserTemplates.ascx" TagName="Template" TagPrefix="uc" %>
<script type="text/javascript">
    $(document).ready(function () {
        $(".edit").live("click", function () {

            var userId = $(this).attr('userid');

            $.ajax({
                type: "POST",
                url: '<%= ResolveUrl("~/Services/UserServices.asmx/GetUserInfo") %>',
                data: "{'userId': '" + userId + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    bindData(data.d);
                },
                error: function (xhr, err) {
                    alert('Cannot process your request!');
                }
            });

        });
    });

    function bindData(data) {
        $('#EditUser').html($('#userInfo').html());
        $('#EditUser').dialog({ title: 'Edit User',
            buttons: [
                            {
                                text: "Cancel",
                                click: function () { $(this).dialog("close"); }
                            }, 
                            {
                                text: "Save",
                                click: function () { $(this).dialog("close"); }
                            }
                         ],
            open: function () {
                if (data != '' && data != undefined) {  
                    var userInfo = $.parseJSON(data);
                    $('#EditUser').find('#txtUserId').attr("value",userInfo.UserId);
                    $('#EditUser').find('#txtEmail').attr("value", userInfo.Email);
                    $('#EditUser').find('#txtDisplayName').attr("value", userInfo.DisplayName);
                    // $('#txtUserId').text(userInfo.UserId);
                }
            }
        });
    }
   
</script>
<div id="EditUser">
</div>
<div class="common-bar">
    <input class="button" type="button" value="Create User" id="btnCreateUser" />
     <input class="button" type="button" value="Delete" id="btnDelete" />
     <input class="button" type="button" value="Active/Deactive" id="btnActive" />
</div>
<div class="clear">
</div>
<asp:Repeater ID="rptUsers" runat="server">    
    <HeaderTemplate>
        <table cellspacing="0">
            <tr>
                <th>
                    UserId
                </th>
                <th>
                    Email
                </th>
                <th>
                    Display Name
                </th>
                <th>
                    Status
                </th>
                <th>
                    Action
                </th>
            </tr>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td>
                <%#DataBinder.Eval(Container.DataItem, "BaseInfo.UserId")%>
            </td>
            <td>
                <%#DataBinder.Eval(Container.DataItem, "BaseInfo.Email")%>
            </td>
            <td>
                <%#DataBinder.Eval(Container.DataItem, "BaseInfo.DisplayName")%>
            </td>
            <td>
                <%#DataBinder.Eval(Container.DataItem, "AccountStatus")%>
            </td>
            <td>
                <img src="../icons/edit.png" class="action-button edit" alt="Edit" title="Edit" userid='<%#DataBinder.Eval(Container.DataItem, "BaseInfo.UserId")%>' />
                <img src="../icons/trash.png" class="action-button" alt="Remove" title="Remove" />
            </td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>
<uc:Template runat="server" />
